package com.dengdai.applibrary.fragmentmanager;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.dengdai.applibrary.R;
import com.dengdai.applibrary.base.BaseActivity;

/**
 * @说明 Fragment管理基类
 * @作者 LY
 * @时间 15/12/24 09:41
 * @版权 Copyright(c) 2015 LY-版权所有
 */
public abstract class BaseFragmentActivity extends BaseActivity {
    private Fragment fragment;
    private FragmentParamEntity params;

    public static final String ENTITY = "entity";
    public static final String TITLE = "title";

    @Override
    public int getLayoutResID() {
        return R.layout.common_base_fragment_activity;
    }

    @Override
    public void initView() {
    }

    @Override
    public void business(Context context) {
        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            params = (FragmentParamEntity) bundle.getSerializable(ENTITY);
            getTitleBarView().setTitle(bundle.getString(TITLE) == null ? "" : bundle.getString(TITLE));
            fragment = initData(params);
            getSupportFragmentManager().beginTransaction().replace(R.id.fl_content, fragment).commit();
        }
    }

    /**
     * 初始化数据
     *
     * @param params 对象类型
     * @return 界面Fragment
     */
    public abstract Fragment initData(FragmentParamEntity params);

}
